﻿CREATE PROCEDURE [dbo].[UpdateParticipant]
    @ParticipantId uniqueidentifier,
	@Activity uniqueidentifier,
	@Person uniqueidentifier,
	@BusinessRole uniqueidentifier,
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE Participant

	SET 

	 Person = @Person,
	 BusinessRole = @BusinessRole,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE ParticipantId = @ParticipantId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM Participant 

	WHERE ParticipantId = @ParticipantId

RETURN 0